package com.googlecode.mysqlcommenter;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.sql.SQLException;
import java.util.List;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.filechooser.FileFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.tree.TreePath;

import org.apache.log4j.BasicConfigurator;
import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle;
import org.springframework.jdbc.CannotGetJdbcConnectionException;

import com.googlecode.mysqlcommenter.model.AbstractDbItem;
import com.googlecode.mysqlcommenter.model.Column;
import com.googlecode.mysqlcommenter.model.ConnTreeModel;
import com.googlecode.mysqlcommenter.model.Db;
import com.googlecode.mysqlcommenter.model.Table;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Gui extends javax.swing.JFrame {

   private JMenuItem helpMenuItem;
   private JMenu jMenu5;
   private JScrollPane jScrollPane1;
   private JEditorPane jEditorPane1;
   private JButton jButton1;
   private JPanel jPanel2;
   private JPanel jPanel1;
   private JTree jTree1;
   private JSplitPane jSplitPane1;
   private JMenuItem saveMenuItem;
   private JPasswordField passwordField;
   private AbstractAction cancelOpenAction;
   private JSplitPane jSplitPane2;
   private JScrollPane jScrollPane4;
   private JScrollPane jScrollPane2;
   private JScrollPane jScrollPane3;
   private JTable jTable1;
   private JLabel jLabel5;
   private JPanel jPanel6;
   private JPanel jPanel4;
   private JLabel charactercount;
   private JLabel dbItemTitle;
   private JPanel jPanel3;
   private AbstractAction exitAction;
   private JMenuItem jMenuItem1;
   private JLabel errorLabel;
   private AbstractAction okOpenAction;
   private JSeparator jSeparator1;
   private JButton jButton3;
   private JButton jButton2;
   private JTextField portTextField;
   private JLabel jLabel4;
   private JLabel jLabel3;
   private JTextField userTextField;
   private JLabel jLabel2;
   private AbstractAction abstractAction2;
   private JMenuItem exitMenuItem;
   private JSeparator jSeparator2;
   private JMenuItem saveAsMenuItem;
   private JFileChooser jFileChooser1;
   private AbstractAction abstractAction1;
   private JTextField hostTextField;
   private JLabel jLabel1;
   private JDialog openDialog;
   private AbstractAction openAction;
   private JMenuItem openFileMenuItem;
   private JMenu jMenu3;
   private JMenuBar jMenuBar1;

   private DBConnection dConnection;

   /**
   * Auto-generated main method to display this JFrame
   */
   public static void main(String[] args) {
      BasicConfigurator.configure();
      SwingUtilities.invokeLater(new Runnable() {
         public void run() {
            Gui inst = new Gui();
            inst.setLocationRelativeTo(null);
            inst.setVisible(true);
         }
      });
   }

   public Gui() {
      super();
      initGUI();

      try {
         getOpenAction().actionPerformed(null);
         addListeners();

      } catch (Exception e) {
         e.printStackTrace();
         jEditorPane1.setText(e.getMessage());
      }

   }

   private void addListeners() {
      MouseListener ml = new MouseAdapter() {
         public void mousePressed(MouseEvent e) {
             int selRow = jTree1.getRowForLocation(e.getX(), e.getY());
             TreePath selPath = jTree1.getPathForLocation(e.getX(), e.getY());
             if(selRow != -1) {
                 if(e.getClickCount() == 1) {
                     mySingleClick(selRow, selPath);
                 }
                 else if(e.getClickCount() == 2) {
                     myDoubleClick(selRow, selPath);
                 }
             }
         }

         private void myDoubleClick(int selRow, TreePath selPath) {
            // TODO Auto-generated method stub

         }

         private void mySingleClick(int selRow, TreePath selPath) {
            try {
               AbstractDbItem dbItem = (AbstractDbItem) selPath.getLastPathComponent();
               dbItemTitle.setText((dbItem).getDescription());
               jEditorPane1.setText(dConnection.getComment(dbItem));
               TableModel jTable1Model =Util.transformToTableModel(dConnection.getSampleData(dbItem));
               jTable1.setModel(jTable1Model);
            } catch (Exception e) {
               jEditorPane1.setText(e.getMessage());
               e.printStackTrace();
            }

         }
     };
     jTree1.addMouseListener(ml);

//     ActionListener al = new ActionListener(){
//
//      public void actionPerformed(ActionEvent e) {
//            dConnection.updateComment((AbstractDbItem) jTree1.getSelectionPath().getLastPathComponent(), jEditorPane1.getText());
//
//      }
//
//     };
//     jButton1.addActionListener(al);

   }

   private void initDBTree()  {
      ConnTreeModel connTreeModel = new ConnTreeModel(dConnection.toString());
      List<String> dbs = dConnection.getDatabases();
      for (String db : dbs) {
         connTreeModel.getDbs().add(new Db(db));
      }

      jTree1.setModel(connTreeModel);
      jTree1.addTreeWillExpandListener(dConnection);
   }

   private void initGUI() {
      try {
         {
            this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            this.setTitle("MySQLCommenter");
         }
         {
            jSplitPane1 = new JSplitPane();
            getContentPane().add(jSplitPane1, BorderLayout.CENTER);
            {
               jScrollPane1 = new JScrollPane();
               jSplitPane1.add(jScrollPane1, JSplitPane.LEFT);
               jSplitPane1.add(getJScrollPane2(), JSplitPane.RIGHT);
               jScrollPane1.setPreferredSize(new java.awt.Dimension(157, 362));
               jScrollPane1.setSize(150, 314);
               {
                  jTree1 = new JTree();
                  jScrollPane1.setViewportView(jTree1);
                  jTree1.setSize(new java.awt.Dimension(131, 311));
               }
            }
            jSplitPane1.setPreferredSize(new java.awt.Dimension(556, 267));

         }
         this.setSize(632, 499);
         {
            jMenuBar1 = new JMenuBar();
            setJMenuBar(jMenuBar1);
            {
               jMenu3 = new JMenu();
               jMenuBar1.add(jMenu3);
               jMenu3.setText("File");
               {
                  openFileMenuItem = new JMenuItem();
                  jMenu3.add(openFileMenuItem);
                  jMenu3.add(getSaveMenuItem());
                  openFileMenuItem.setText("Open");
                  openFileMenuItem.setAction(getOpenAction());
               }
               {
                  saveAsMenuItem = new JMenuItem();
                  jMenu3.add(saveAsMenuItem);
                  saveAsMenuItem.setText("Export");
                  saveAsMenuItem.setAction(getAbstractAction1());
               }
               {
                  jSeparator2 = new JSeparator();
                  jMenu3.add(jSeparator2);
               }
               {
                  exitMenuItem = new JMenuItem();
                  jMenu3.add(exitMenuItem);
                  exitMenuItem.setText("Exit");
                  exitMenuItem.setAction(getExitAction());
               }
            }
            {
               jMenu5 = new JMenu();
               jMenuBar1.add(jMenu5);
               jMenu5.setText("Help");
               {
                  helpMenuItem = new JMenuItem();
                  jMenu5.add(helpMenuItem);
                  jMenu5.add(getJMenuItem1());
                  helpMenuItem.setText("Help");
               }
            }
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
   }

   private AbstractAction getAbstractAction1() {
      if(abstractAction1 == null) {
         abstractAction1 = new AbstractAction("Export", null) {
            public void actionPerformed(ActionEvent evt) {
               try {
                  JFileChooser fileChooser1 = getJFileChooser1();
                  fileChooser1.setFileFilter(new FileFilter(){

                     @Override
                     public boolean accept(File f) {
                        return f.isDirectory() || f.getName().endsWith(".html");
                     }

                     @Override
                     public String getDescription() {
                        return "html files";
                     }

                  });
                  int returnVal = fileChooser1.showSaveDialog(Gui.this);
                  if (returnVal==JFileChooser.APPROVE_OPTION && fileChooser1.getSelectedFile()!=null){
                     //get full db
                     Db db =dConnection.getDb((AbstractDbItem)jTree1.getLastSelectedPathComponent());

                     new Export().doExport(db, fileChooser1.getSelectedFile());
                  }
               } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
               }
            }
         };
         abstractAction1.putValue(javax.swing.Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("alt pressed E"));
      }
      return abstractAction1;
   }

   private JFileChooser getJFileChooser1() {
      if(jFileChooser1 == null) {
         jFileChooser1 = new JFileChooser();
      }
      return jFileChooser1;
   }

   private JMenuItem getSaveMenuItem() {
      if(saveMenuItem == null) {
         saveMenuItem = new JMenuItem();
         saveMenuItem.setText("Save");
         saveMenuItem.setAction(getAbstractAction2());
      }
      return saveMenuItem;
   }

   private AbstractAction getAbstractAction2() {
      if(abstractAction2 == null) {
         abstractAction2 = new AbstractAction("Save", null) {
            public void actionPerformed(ActionEvent evt) {
               dConnection.updateComment((AbstractDbItem) jTree1.getSelectionPath().getLastPathComponent(), jEditorPane1.getText());
            }
         };
         abstractAction2.putValue(javax.swing.Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("alt pressed S"));
      }
      return abstractAction2;
   }

   private AbstractAction getOpenAction() {
      if(openAction == null) {
         openAction = new AbstractAction("Open", null) {
            public void actionPerformed(ActionEvent evt) {
               getOpenDialog().pack();
               getOpenDialog().setLocationRelativeTo(null);
               getOpenDialog().setVisible(true);
            }
         };
         openAction.putValue(javax.swing.Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("alt pressed O"));
      }
      return openAction;
   }

   private JDialog getOpenDialog() {
      if(openDialog == null) {
         openDialog = new JDialog(this);
         GroupLayout openDialogLayout = new GroupLayout((JComponent)openDialog.getContentPane());
         openDialog.getContentPane().setLayout(openDialogLayout);
         openDialog.setPreferredSize(new java.awt.Dimension(311, 275));
         openDialog.setTitle("Open database");
         openDialog.setModal(true);
         openDialog.setSize(311, 275);
         openDialogLayout.setHorizontalGroup(openDialogLayout.createParallelGroup()
            .add(GroupLayout.LEADING, getJSeparator1(), 0, 303, Short.MAX_VALUE)
            .add(openDialogLayout.createSequentialGroup()
                .add(40)
                .add(openDialogLayout.createParallelGroup()
                    .add(GroupLayout.LEADING, getErrorLabel(), GroupLayout.PREFERRED_SIZE, 229, GroupLayout.PREFERRED_SIZE)
                    .add(openDialogLayout.createSequentialGroup()
                        .add(openDialogLayout.createParallelGroup()
                            .add(GroupLayout.LEADING, openDialogLayout.createSequentialGroup()
                                .add(27)
                                .add(getJButton2(), GroupLayout.PREFERRED_SIZE, 74, GroupLayout.PREFERRED_SIZE))
                            .add(GroupLayout.LEADING, openDialogLayout.createSequentialGroup()
                                .add(getJLabel4(), GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
                                .add(23))
                            .add(GroupLayout.LEADING, openDialogLayout.createSequentialGroup()
                                .add(getJLabel3(), GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
                                .add(23))
                            .add(GroupLayout.LEADING, openDialogLayout.createSequentialGroup()
                                .add(getJLabel2(), GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
                                .add(23))
                            .add(GroupLayout.LEADING, openDialogLayout.createSequentialGroup()
                                .add(getJLabel1(), GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
                                .add(23)))
                        .addPreferredGap(LayoutStyle.UNRELATED)
                        .add(openDialogLayout.createParallelGroup()
                            .add(GroupLayout.LEADING, getHostTextField(), GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
                            .add(GroupLayout.LEADING, getUserTextField(), GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
                            .add(GroupLayout.LEADING, getPasswordField(), GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
                            .add(GroupLayout.LEADING, getPortTextField(), GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
                            .add(GroupLayout.LEADING, openDialogLayout.createSequentialGroup()
                                .addPreferredGap(LayoutStyle.RELATED)
                                .add(getJButton3(), GroupLayout.PREFERRED_SIZE, 74, GroupLayout.PREFERRED_SIZE)
                                .add(31)))))
                .addContainerGap(34, 34)));
         openDialogLayout.linkSize(new Component[] {getJLabel1(), getJLabel2(), getJLabel3(), getJLabel4()}, GroupLayout.HORIZONTAL);
         openDialogLayout.linkSize(new Component[] {getHostTextField(), getUserTextField(), getPasswordField(), getPortTextField()}, GroupLayout.HORIZONTAL);
         openDialogLayout.linkSize(new Component[] {getJButton3(), getJButton2()}, GroupLayout.HORIZONTAL);
         openDialogLayout.setVerticalGroup(openDialogLayout.createSequentialGroup()
            .addContainerGap()
            .add(getErrorLabel(), GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(LayoutStyle.UNRELATED)
            .add(openDialogLayout.createParallelGroup(GroupLayout.BASELINE)
                .add(GroupLayout.BASELINE, getHostTextField(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
                .add(GroupLayout.BASELINE, getJLabel1(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(LayoutStyle.RELATED)
            .add(openDialogLayout.createParallelGroup(GroupLayout.BASELINE)
                .add(GroupLayout.BASELINE, getUserTextField(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
                .add(GroupLayout.BASELINE, getJLabel2(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(LayoutStyle.UNRELATED)
            .add(openDialogLayout.createParallelGroup(GroupLayout.LEADING)
                .add(GroupLayout.LEADING, getPasswordField(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
                .add(GroupLayout.LEADING, getJLabel3(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
            .add(16)
            .add(openDialogLayout.createParallelGroup(GroupLayout.BASELINE)
                .add(GroupLayout.LEADING, getPortTextField(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
                .add(GroupLayout.LEADING, getJLabel4(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(LayoutStyle.UNRELATED)
            .add(getJSeparator1(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
            .add(17)
            .add(openDialogLayout.createParallelGroup(GroupLayout.BASELINE)
                .add(GroupLayout.BASELINE, getJButton3(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
                .add(GroupLayout.BASELINE, getJButton2(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
            .addContainerGap(19, 19));
         openDialogLayout.linkSize(new Component[] {getPasswordField(), getJLabel3()}, GroupLayout.VERTICAL);
         openDialogLayout.linkSize(new Component[] {getPortTextField(), getJLabel4()}, GroupLayout.VERTICAL);
         openDialogLayout.linkSize(new Component[] {getJButton3(), getJButton2()}, GroupLayout.VERTICAL);
      }
      return openDialog;
   }

   private JLabel getJLabel1() {
      if(jLabel1 == null) {
         jLabel1 = new JLabel();
         jLabel1.setText("Hostname");
      }
      return jLabel1;
   }

   private JTextField getHostTextField() {
      if(hostTextField == null) {
         hostTextField = new JTextField();
         hostTextField.setText("localhost");
      }
      return hostTextField;
   }

   private JLabel getJLabel2() {
      if(jLabel2 == null) {
         jLabel2 = new JLabel();
         jLabel2.setText("User");
      }
      return jLabel2;
   }

   private JTextField getUserTextField() {
      if(userTextField == null) {
         userTextField = new JTextField();
         userTextField.setText("root");
      }
      return userTextField;
   }

   private JLabel getJLabel3() {
      if(jLabel3 == null) {
         jLabel3 = new JLabel();
         jLabel3.setText("Password");
      }
      return jLabel3;
   }

   private JPasswordField getPasswordField() {
      if(passwordField == null) {
         passwordField = new JPasswordField();
      }
      return passwordField;
   }

   private JLabel getJLabel4() {
      if(jLabel4 == null) {
         jLabel4 = new JLabel();
         jLabel4.setText("Port");
      }
      return jLabel4;
   }

   private JTextField getPortTextField() {
      if(portTextField == null) {
         portTextField = new JTextField();
         portTextField.setText("3306");
      }
      return portTextField;
   }

   private JButton getJButton2() {
      if(jButton2 == null) {
         jButton2 = new JButton();
         jButton2.setText("OK");
         jButton2.setAction(getOkOpenAction());
      }
      return jButton2;
   }

   private JButton getJButton3() {
      if(jButton3 == null) {
         jButton3 = new JButton();
         jButton3.setText("Cancel");
         jButton3.setAction(getCancelOpenAction());
      }
      return jButton3;
   }

   private JSeparator getJSeparator1() {
      if(jSeparator1 == null) {
         jSeparator1 = new JSeparator();
      }
      return jSeparator1;
   }

   private AbstractAction getOkOpenAction() {
      if(okOpenAction == null) {
         okOpenAction = new AbstractAction("OK", null) {
            public void actionPerformed(ActionEvent evt) {
               try {
                  dConnection = new DBConnection(hostTextField.getText(),
                        portTextField.getText(), userTextField.getText(),
                        new String(passwordField.getPassword()));
                  initDBTree();
                  getOpenDialog().dispose();
               } catch (CannotGetJdbcConnectionException e) {
                  errorLabel.setText("ERROR: cannot open database");
               }
            }
         };
      }
      return okOpenAction;
   }

   private AbstractAction getCancelOpenAction() {
      if(cancelOpenAction == null) {
         cancelOpenAction = new AbstractAction("Cancel", null) {
            public void actionPerformed(ActionEvent evt) {
               getOpenDialog().dispose();
            }
         };
      }
      return cancelOpenAction;
   }

   private JLabel getErrorLabel() {
      if(errorLabel == null) {
         errorLabel = new JLabel();
         errorLabel.setForeground(new java.awt.Color(255,0,0));
      }
      return errorLabel;
   }

   private JMenuItem getJMenuItem1() {
      if(jMenuItem1 == null) {
         jMenuItem1 = new JMenuItem();
         jMenuItem1.setText("jMenuItem1");
         jMenuItem1.setAction(getExitAction());
      }
      return jMenuItem1;
   }

   private AbstractAction getExitAction() {
      if(exitAction == null) {
         exitAction = new AbstractAction("Exit", null) {
            public void actionPerformed(ActionEvent evt) {
               System.exit(0);
            }
         };
         exitAction.putValue(javax.swing.Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl alt pressed X"));
      }
      return exitAction;
   }

   private JPanel getJPanel3() {
      if(jPanel3 == null) {
         jPanel3 = new JPanel();
         FlowLayout jPanel3Layout = new FlowLayout();
         jPanel3.setLayout(jPanel3Layout);
//         jPanel3.setPreferredSize(new java.awt.Dimension(410, 56));
         jPanel3.add(getDbItemTitle());
      }
      return jPanel3;
   }

   private JLabel getDbItemTitle() {
      if(dbItemTitle == null) {
         dbItemTitle = new JLabel();
         dbItemTitle.setPreferredSize(new java.awt.Dimension(364, 29));
      }
      return dbItemTitle;
   }

   private JLabel getCharactercount() {
      if(charactercount == null) {
         charactercount = new JLabel();
         charactercount.setPreferredSize(new java.awt.Dimension(448, 28));
         charactercount.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
      }
      return charactercount;
   }

   private JPanel getJPanel4() {
      if(jPanel4 == null) {
         jPanel4 = new JPanel();
         BorderLayout jPanel4Layout = new BorderLayout();
         jPanel4.setLayout(jPanel4Layout);
         jPanel4.add(getJScrollPane4(),BorderLayout.CENTER);

      }
      return jPanel4;
   }

   private JPanel getJPanel6() {
      if(jPanel6 == null) {
         jPanel6 = new JPanel();
         BorderLayout jPanel6Layout = new BorderLayout();
         jPanel6.setLayout(jPanel6Layout);
         jPanel6.setPreferredSize(new java.awt.Dimension(362, 185));
         jPanel6.add(getJLabel5(), BorderLayout.NORTH);
         jPanel6.add(getJScrollPane3(), BorderLayout.CENTER);
      }
      return jPanel6;
   }

   private JLabel getJLabel5() {
      if(jLabel5 == null) {
         jLabel5 = new JLabel();
         jLabel5.setText("Sample data");
      }
      return jLabel5;
   }

   private JTable getJTable1() {
      if(jTable1 == null) {
         TableModel jTable1Model =
            new DefaultTableModel(
                  new String[][] { { " ", " " }, { " ", " " } },
                  new String[] { " ", " " });
         jTable1 = new JTable();
         jTable1.setModel(jTable1Model);
         jTable1.setPreferredSize(new java.awt.Dimension(450, 185));
         jTable1.setEnabled(false);
      }
      return jTable1;
   }

   private JScrollPane getJScrollPane3() {
      if(jScrollPane3 == null) {
         jScrollPane3 = new JScrollPane();
//         jScrollPane3.setPreferredSize(new java.awt.Dimension(427, 32));
         jScrollPane3.setViewportView(getJTable1());
      }
      return jScrollPane3;
   }

   private JSplitPane getJSplitPane2() {
      if(jSplitPane2 == null) {
         jSplitPane2 = new JSplitPane();
         {
            jPanel1 = new JPanel();
            jSplitPane2.add(jPanel1, JSplitPane.TOP);
            jSplitPane2.add(getJPanel6(), JSplitPane.BOTTOM);
            BorderLayout jPanel1Layout = new BorderLayout();
            jPanel1.setLayout(jPanel1Layout);
            jPanel1.setPreferredSize(new java.awt.Dimension(404, 168));
            {
               jPanel2 = new JPanel();
               FlowLayout jPanel2Layout = new FlowLayout();
               jPanel2.setLayout(jPanel2Layout);
               jPanel1.add(getJPanel4(), BorderLayout.CENTER);
               jPanel1.add(jPanel2, BorderLayout.SOUTH);
               jPanel2.setPreferredSize(new java.awt.Dimension(450, 33));
               {
                  jButton1 = new JButton();
                  jPanel2.add(jButton1);
                  jButton1.setText("save");
                  jButton1.setAction(getAbstractAction2());
               }
            }
         }
         jSplitPane2.setOrientation(JSplitPane.VERTICAL_SPLIT);
      }
      return jSplitPane2;
   }

   private JScrollPane getJScrollPane2() {
      if(jScrollPane2 == null) {
         jScrollPane2 = new JScrollPane();
         jScrollPane2.setViewportView(getJSplitPane2());
      }
      return jScrollPane2;
   }

   private JScrollPane getJScrollPane4() {
      if(jScrollPane4 == null) {
         jScrollPane4 = new JScrollPane();
         {
            jEditorPane1 = new JEditorPane();
            jScrollPane4.setViewportView(jEditorPane1);
            jPanel4.setPreferredSize(new java.awt.Dimension(493, 235));
            jPanel4.add(getJScrollPane4(), BorderLayout.CENTER);
            jPanel4.add(getCharactercount(), BorderLayout.SOUTH);
            jScrollPane4.setPreferredSize(new java.awt.Dimension(407, 68));
            jEditorPane1.setVisible(true);
            jEditorPane1.setPreferredSize(new java.awt.Dimension(428, 64));
            jEditorPane1.addKeyListener(new KeyAdapter() {
               public void keyReleased(KeyEvent evt) {
                  System.out.println("jEditorPane1.keyTyped, event="+evt);
                  charactercount.setText("Length: "+jEditorPane1.getText().length());
                  if (jEditorPane1.getText().length()>60 && jTree1.getSelectionPath().getLastPathComponent() instanceof Table){
                     charactercount.setText("Max 60 characters for table comment");
                     jEditorPane1.setText(jEditorPane1.getText().substring(0,60));
                  }
                  if (jEditorPane1.getText().length()>255 && jTree1.getSelectionPath().getLastPathComponent() instanceof Column){
                     charactercount.setText("Max 255 characters for column comment");
                     jEditorPane1.setText(jEditorPane1.getText().substring(0,255));
                  }
               }
            });
            jPanel1.add(getJPanel3(), BorderLayout.NORTH);
         }
      }
      return jScrollPane4;
   }

}
